import { Applet } from "@/api/interface/iot";
import { GlobalStore } from "@/stores";
import { openWin } from "@/utils/routerUtil";
import { ElMessage } from "element-plus";
export const useApplet = () => {
	/**
	 * 跳转到应用系统
	 * @param applet
	 * @returns
	 */
	const gotoAppletPage = (applet: Applet.ResUserApplet) => {
		if (!applet.home) {
			ElMessage.warning("当前应用不是一个Web应用");
			return;
		}
		if (!applet.home.startsWith("http")) {
			let server = import.meta.env.DEV ? "http://172.16.22.132:9000" : window.location.origin;
			applet.home = server + applet.home;
		}
		let page = `${applet.home}?redirect=${applet.index || ""}&token=${GlobalStore().token}`;
		openWin(page);
	};
	return {
		gotoAppletPage
	};
};
